import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by twer on 3/10/14.
 */
public class Biblioteca {
    private ArrayList<MyUser> users;
    private ArrayList<String> activeUsers = new ArrayList<String>();

    private ArrayList<Movie> movielist;
    private ArrayList<String> bookList;
    private String[] menuOptions;
    Map<String, String> checkoutList = new HashMap<String, String>();

    public Biblioteca(ArrayList<String> booklist, ArrayList<Movie> movielist, ArrayList<MyUser> users) {
        this.bookList = booklist;
        this.movielist = movielist;
        this.users = users;
    }

    public Biblioteca(String[] menu) {

        menuOptions = menu;
    }

    public Biblioteca() {

    }

    public String sayWelcome() {
        return "Welcome";
    }

    public ArrayList<String> showBookList() {
        return bookList;
    }

    public String[] getMenuOptions() {
        return menuOptions;
    }

    public String validMenuOption(String menuoption) {
        return "Select a valid option!";
    }

    public String checkout(MyUser user, String bookname) {
        if(!activeUsers.contains(user.getLibraryNum()))
            return "error!";
        if(!bookList.contains(bookname))
            return "That book is not available";
        checkoutList.put(bookname, user.getLibraryNum());
        bookList.remove(bookname);
        return "Thank you! Enjoy the book";
    }

    public String getCustomerNameBy(String bookname) {
        return checkoutList.get(bookname);
    }

    public String returnBook(String bookName) {
        if(!checkoutList.containsKey(bookName))
            return "That is not a valid book to return.";
        checkoutList.remove(bookName);
        bookList.add(bookName);
        return "Thank you for returning the book.";
    }

    public ArrayList<Movie> showMovies() {
        return movielist;
    }

    public String checkoutMovie(String movieName) {
        return "Checkout movie successfully!";
    }

    public boolean login(MyUser myuser) {
        for(MyUser user : users)
        {
            if(user.getLibraryNum().equals(myuser.getLibraryNum()) && user.getPassword().equals(myuser.getPassword()))
            {
                activeUsers.add(myuser.getLibraryNum());
                return true;
            }
        }
        return false;
    }
}
